/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.gob.fonafe.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;
import pe.gob.fonafe.dao.BannerDAO;
import pe.gob.fonafe.dao.impl.stored.ActualizaBannerSP;
import pe.gob.fonafe.dao.impl.stored.ObtenerBannerSP;
import pe.gob.fonafe.domain.BannerBean;

/**
 *
 * @author czela
 */
@Repository
public class BannerDAOImpl extends SimpleJdbcDaoSupport implements BannerDAO{

    private static final Logger logger = Logger.getLogger(BannerDAOImpl.class);

    @Autowired
    public BannerDAOImpl(DataSource dataSource) {
        super.setDataSource(dataSource);
    }

    public List<BannerBean> obtenerBanner() {
        List<BannerBean> obtenerBanner = new ArrayList<BannerBean>();
        try{
            ObtenerBannerSP sp = new ObtenerBannerSP(getDataSource());
            Map results = sp.execute();
            obtenerBanner = (List<BannerBean>)results.get("cCursor");
        }catch(Exception ex){
            ex.printStackTrace();
            logger.error(ex);
        }
        return obtenerBanner;
    }

    public String[] actualizarBanner(BannerBean bean) {
        String[] outPuts = new String[2];
        try{
            ActualizaBannerSP sp = new ActualizaBannerSP(getDataSource());
            Map results = sp.execute(bean);
            outPuts[0] = (String)results.get("V_EXITO");
            outPuts[1] = (String)results.get("V_MENSAJE");
        }catch(Exception ex){
            ex.printStackTrace();
            logger.error(ex);
        }
        return outPuts;
    }

}
